<footer id="footer">
    <div class="container">
      <div class="row">
        <span id="icp" class="pull-left gray-link">
            © 2005－2015 wowli.com, all rights reserved
        </span>
        <a href="javascript:;" style="display: none;"></a>
        <span class="pull-right">
            <a href="javascript:;">关于哇礼</a>
            · <a href="javascript:;">在哇礼工作</a>
            · <a href="javascript:;">联系我们</a>
            · <a href="javascript:;">免责声明</a>
            · <a href="javascript:;">帮助中心</a>
            · <a href="javascript:;">移动应用</a>
        </span>       
      </div>
    </div>
  </footer>
  <!-- 登录model开始 -->
  <div class="modals">
    <div class="modal fade" id="login-modal">
        <div class="modal-dialog_wrapper">
            <div class="modal-dialog modal-dialog--front modal-dialog--signin">
                <div class="modal-content">
                    <button class="close" data-dismiss="modal" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                    <div class="modal-body">
                        <form id="login_form" class="simple_form new_user" action="{:U('user/Index/login')}" accept-charset="UTF-8" data-remote="true" method="post" novalidate="true">
                            <input name="utf8" type="hidden" value="✓">
                            <legend>登录</legend>
                            <div class="form-main">
                                <div class="form-group col-sm-6">
                                    <label class="sr-only">邮件地址</label>
                                    <input required="required" placeholder="邮件地址" class="form-control" data-message-error="邮箱格式错误" type="email" name="user[email]" id="login_email" data-event="validate"><span class="button--clear fa fa-times"></span>
                                    <ul class="help-block"></ul>
                                </div>
                                <div class="form-group col-sm-6">
                                    <label class="sr-only">密码</label>
                                    <input required="required" placeholder="密码" class="form-control" type="password" name="user[password]" id="login_password" data-event="validate"><span class="button--clear fa fa-times"></span>
                                    <ul class="help-block"></ul>
                                </div>
                                <input type="hidden" name="redirect_from" id="redirect_from">
                            </div>
                            <div class="form-group addon clearfix">
                                <div class="checkbox pull-left" id="remember_me">
                                    <label>
                                        <input name="user[remember_me]" type="hidden" value="0">
                                        <input type="checkbox" value="1" checked="checked" name="user[remember_me]" id="user_remember_me">记住我</label>
                                </div>
                                <a class="pull-right" data-toggle="modal" data-dismiss="modal" href="#find_password_modal">
                                <i class="fa fa-question-circle"></i>忘记密码？</a>
                            </div>
                            <div class="form-group form-results hidden" id="sign_in_alert_field">用户名或密码错误，请重新输入</div>
                            <div class="form-group form-actions">
                                <input type="submit" name="commit" value="登录" class="btn btn--blue_light" data-category="user" data-action="login" data-label="email">
                            </div>
                        </form>
                        <section class="auth">
                            <h6>使用社交账号登录</h6>
                            <p>
                            <a class="btn btn--icon btn--blue_light" title="用微信登录" data-category="user" data-action="login" data-label="wechat" href="/users/auth/wechat_web?state=%2Fdiscover"><i class="fa fa-weixin"></i></a>
                            <a class="btn btn--icon btn--blue_light" title="用微博登录" data-category="user" data-action="login" data-label="weibo" href="/users/auth/weibo?state=%2Fdiscover"><i class="fa fa-weibo"></i></a>
                            </p>
                        </section>
                        <footer class="section-footer"><a class="modal-flipper" href="#">注册<em class="logo">猫耳</em><i class="fa fa-angle-right"></i></a></footer>
                    </div>
                </div>
            </div>
            <div class="modal-dialog modal-dialog--back modal-dialog--signup">
                <div class="modal-content">
                    <button class="close" data-dismiss="modal" type="button"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                    <div class="modal-body">
                        <form id="signup_form" class="simple_form new_user" action="{:U('User/Index/register')}" accept-charset="UTF-8" data-remote="true" method="post" novalidate="true">
                            <input name="utf8" type="hidden" value="✓">
                            <legend>注册</legend>
                            <div class="form-main">
                                <div class="form-group col-sm-6">
                                    <label class="sr-only" for="user_name">昵称</label>
                                    <input placeholder="用户名（少于 3~20 个字符）" class="form-control" required="required" maxlength="20" data-message-error="用户名必须介于介于 3~20个字符" size="20" type="text" value="" name="user[user_name]" id="user_name" data-event="validate"><span class="button--clear fa fa-times"></span>
                                    <ul class="help-block"></ul>
                                </div>
                                <div class="form-group col-sm-6">
                                    <label class="sr-only" for="user_email">邮件地址</label>
                                    <input placeholder="邮件地址" class="form-control" required="required" data-message-error="邮箱格式错误" type="email" name="user[email]" id="user_email" data-event="validate"><span class="button--clear fa fa-times"></span>
                                    <ul class="help-block"></ul>
                                </div>
                                <div class="clearfix"></div>
                                <div class="form-group col-sm-6">
                                    <label class="sr-only" for="user_password">密码</label>
                                    <input placeholder="密码（至少 6 个字符）" class="form-control" required="required" minlength="6" data-message-error="密码至少 6 个字符" type="password" name="user[password]" id="user_password" data-event="validate"><span class="button--clear fa fa-times"></span>
                                    <ul class="help-block"></ul>
                                </div>
                                <div class="form-group col-sm-6 signup_form-captcha">
                                    <label class="sr-only" for="captcha">验证码</label>
                                    <div class="input-group">
                                        <input type="text" name="captcha" id="captcha" autocomplete="off" required="required" class="form-control" data-parent=".form-group" placeholder="输入验证码" data-event="validate">
                                        <input type="hidden" name="captcha_key" id="simple-captcha-hidden-field-simple_captcha-28e145c6347" value="28e145c634754b73369a62a7156e795d0f880b66">
                                        <div class="input-group-addon" style="padding:0px;">
                                            <a rel="nofollow" title="换一张" data-remote="true" href="javascript:;" onclick="this.children[0].src='__ROOT__/index/get_code?id='+Math.random()+1"><img src="__ROOT__/index/get_code" id="simple_captcha-28e145c6347" alt="captcha" class="js-lazy" data-original=""  style="visibility: visible; display: inline;width:100px;height:44px;"></a>
                                        </div>
                                    </div>
                                    <ul class="help-block"></ul>
                                </div>
                            </div>
                            <div class="form-group clearfix">
                                <div class="checkbox text-center">
                                    <label>
                                        <input type="checkbox" name="agreement" id="user_agreement" value="true" checked="checked">同意<a target="_blank" href="/user_agreement">《&nbsp;<em class="logo">猫耳</em>&nbsp;用户协议》</a></label>
                                </div>
                            </div>
                            <input type="hidden" name="path" id="path" value="/discover">
                            <input type="hidden" name="redirect_from" id="redirect_from">
                            <div class="form-group form-actions">
                                <input type="submit" name="commit" value="注册" class="btn btn--blue_light" data-category="user" data-action="register" data-label="email">
                            </div>
                        </form>
                        <section class="auth">
                            <h6>使用社交账号登录</h6>
                            <p>
                              <a class="btn btn--icon btn--blue_light" title="用微信登录" data-category="user" data-action="login" data-label="wechat" href="/users/auth/wechat_web?state=%2Fdiscover"><i class="fa fa-weixin"></i></a>
                              <a class="btn btn--icon btn--blue_light" title="用微博登录" data-category="user" data-action="login" data-label="weibo" href="/users/auth/weibo?state=%2Fdiscover"><i class="fa fa-weibo"></i></a>
                            </p>
                        </section>
                        <footer class="section-footer"><a class="modal-flipper" href="#"><i class="fa fa-angle-left"></i>登录<em class="logo">猫耳</em></a></footer>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal" id='add_drawer'>
        <div class="modal-wrapper">
            <div class="modal-dialog modal-dialog-drawer">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title box-title">添加好礼到抽屉</h4>
                    </div>
                    <div class="modal-body">
                        <div class="preview">
                            <img class="img-responsive" src="" id='J_goodsCoverPreview' data-goods-id=''>
                            <div style="display: block" class="stop"></div>
                        </div>
                        <div class="right-part">
                            <div class="board-list use-default-board inited" data-board-id="">
                                <div class="current">
                                    <div class="name"></div>
                                    <div class="arrow"></div>
                                </div>
                                <div style="display:none" class="drop-list">
                                    <div class="boards">
                                        <div class="group recent">
                                            <div class="side-title"></div>
                                            <div class="selections">
                                                <foreach name="drawer_list" item="vo">
                                                    <a title="{$vo.title}" data-board-id="{$vo.id}" class="board">{$vo.title}</a>
                                                </foreach>
                                            </div>
                                        </div>
                                        <!-- <div class="group">
                                            <div class="side-title">
                                                <div class="icon">D</div>
                                            </div>
                                            <div class="selections">
                                            <a title="灯具" data-board-id="24039054" class="board">灯具</a>
                                            </div>
                                        </div> -->
                                    </div>
                                    <div style="display: none" class="filtrate">
                                    	<div class="group create">
                                    	    <div class="side-title"></div>
                                    	    <div class="selections"><a data-name="" class="board create-board selected" id="create_new_board">创建画板“<span id="new_board_name"></span>”</a></div>
                                    	</div>
                                    	<div class="group">
                                    	    <div class="side-title"></div>
                                    	    <div class="selections"></div>
                                    	</div>
                                    </div>
                                    <div class="filter">
                                        <input type="text" placeholder="快速筛选/创建抽屉" class="clear-input" id="filter_create_board">
                                    </div>
                                </div>
                            </div>
                            <div class="text-block">
                                <textarea class="clear-input description" autocomplete="off"></textarea>
                                <ul class="ac-choices" style="display: none; z-index: 42; opacity: 0;"></ul>
                                <div class="tag-bar">
                                    <div class="normal" style="display: none;"><span class="title">推荐标签</span><span class="tags"></span></div>
                                    <div style="display: none" class="more"><span class="title">更多标签</span><span class="tags"></span></div>
                                    <div style="display: block;" class="tip">通过给采集添加 #标签#，更好地整理采集</div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer bottom-part">
                        <div class="shares"><span>分享到：</span>
                            <div data-key="weibo" data-flag="1" class="share weibo active">
                            <div class="selection"></div>新浪微博</div>
                        </div>
                        <div class="buttons">
                            <a href="javascript:;" class="action btn btn18 rbtn J_DrawrAddGoods" style="color:#fff;"><span class="text"> 发布</span></a>
                        </div>
                    </div>
                </div><!-- /.modal-content -->
            </div>
        </div>
    </div>
  </div>
  <!-- 登录model结束 -->
  </body>
  <script type="text/javascript">
    var api = {
        "loginUrl"       : '{:U('User/login')}',
        "registerUrl"    : '{:U('User/register')}',
        "createBoardUrl" : '{:U('Drawer/async_create_drawer')}',
        'addDrawerGoods' : '{:U('Drawer/drawer_add_goods')}',
    };

    $(function() {
      $('.modal-flipper').click(function() {
        if($('.modal-dialog_wrapper').hasClass('is-flipped')) {
          $('.modal-dialog_wrapper').removeClass('is-flipped');
        } else {
          $('.modal-dialog_wrapper').addClass('is-flipped');
        }
      });

      //登录和注册#signin_form,
      $('#signup_form').submit(function() {
        var userName     = $("#user_name").val(),
            userEmail    = $('#user_email').val(),
            userPassword = $('#user_password').val(),
            code         = $('#captcha').val();

        $.post(api.registerUrl, { user_name:userName, user_email:userEmail, user_password :userPassword, code:code, redirect_url: window.location.href }, function(data) {
            console.log(data);
            if( data.status != 'succ') {
                alert(data.msg);return;
            }
            if(data.redirect_url) window.location.href = data.redirect_url;
        }, 'json')
        return false;
      });

      $('#login_form').submit(function() {
        var userPass = $('#login_password').val(),
            userEmail= $('#login_email').val();

        $.post(api.loginUrl, { user_pass: userPass, user_email:userEmail, redirect_url: window.location.href }, function(data) {
            console.log(data);
            if(!data.status) {
                alert(data.msg);
                return false;
            }
            if (data.redirect_url) window.location.href = data.redirect_url;
        }, 'json')
        //阻止默认事件
        return false;
      });

      //发布商品和文章
      $('.J_UserAction').bind('click', function() {
        $('.J_ActionWrap').toggleClass('hidden');
      });

      //添加到抽屉效果
      $('.current').click(function() {
      	$('.drop-list').css('display', 'block');
      });

      $('.boards .selections a').click(function() {
      	// $(this).css('background-color', 'red');
      	setCurrent($(this).text(), $(this).attr('data-board-id'));
      	$('.drop-list').css('display', 'none');
      })

      //设置当前的分类名称和值
      function setCurrent(name, id) {
      	$('.current .name').text(name);
      	$('.current').parent().attr('data-board-id', id);
      }

      $('#filter_create_board').bind('keyup', filterCreateBoard);
      //创建画板
      function filterCreateBoard() {
        var boardName = $('#filter_create_board').val();
        if (boardName) {
            if (!$('.filtrate:visible').length) {
                $('.boards').css('display','none');
                $('.filtrate').css('display','block');
            }
            $('#new_board_name').text(boardName);
            $('#create_new_board').attr('data-name', boardName);
        } else {
            if ($('.filtrate:visible').length) {
                $('.boards').css('display','block');
                $('.filtrate').css('display','none');
            }
        }
      }

      //切换面板的显示和隐藏
      function toggleShow() {
        if (!$('.filtrate:visible').length) {
            $('.boards').css('display','none');
            $('.filtrate').css('display','block');
        } else {
            $('.boards').css('display','block');
            $('.filtrate').css('display','none');
        }
      }

      //绑定创建画板事件
      $('#create_new_board').bind('click', createBoard);
      //创建画板
      function createBoard() {
        if (!isLogin) {
            $('.login').trigger('click');
            return false;
        };

        var boardName = $('#new_board_name').text();
        if (!boardName) return false;

        $.post(api.createBoardUrl, { "title":boardName }, function(data) {
            if (data.status == 'error') {
                alert(data.msg);
                if(data.redirect_url){
                    window.location.href =  data.redirect_url;
                }
            } else {
                $('.drop-list').css('display','none');
                $('.filtrate').css('display','none');
                $('.boards').css('display','block');
                setCurrent(boardName, data.msg);
                resetCreateBoard();
            }
        }, 'json');
      }

      //重置创建画板的表单
      function resetCreateBoard() {
        $('#filter_create_board').val('');
        $('#new_board_name').text('');
        $('#create_new_board').attr('data-name', '');
      }

      $('.J_DrawrAddGoods').on('click', drawerAddGoods);
      //添加商品到抽屉
      function drawerAddGoods(e) {
        //isLogin 在头部定义
        e.preventDefault();
        if (!isLogin) {
            $('.login').trigger('click');
            return false;
        };

        var goodsId  = $('#J_goodsCoverPreview').attr('data-goods-id');
        var drawerId = $('.board-list').attr('data-board-id');
        var intro    = $('.description').val();

        if (!parseInt(goodsId)) {
            alert('请先选择商品');
            return;
        };

        if (!parseInt(drawerId)) {
            alert('请选择对应的抽屉');
            return;
        };


        //添加商品到抽屉
        var info = {
            'drawer_id' : drawerId,
            'goods_id'  : goodsId,
            'intro'     : intro
        };
        $.post(api.addDrawerGoods, info, function(data) {
            if (data.status != 'succ') {
                alert(data.msg);
                if (data.redirect_url) {
                    window.location.href = data.redirect_url;
                };
            } else {
                $('.description').val('');
                alert('添加成功');
                $('#add_drawer').find('.close').trigger('click');
            }
        }, 'json');
      }


      function checkLogin() {
        return isLogin;
      }

      var hideDrawerTime = null;
      $('.J_GoodsCover').mouseover(function(ev){
        $(this).closest('.J_ItemWrap').find('.card-actions').show();
      });

      $('.J_GoodsCover').mouseout(function(){
        $this= $(this);
        hideDrawerTime = setTimeout(function() {
            $this.closest('.J_ItemWrap').find('.card-actions').hide();
        }, 200)
      });

      $('.card-actions').hover(function() {
        clearTimeout(hideDrawerTime);
      }, function() {
        $(this).closest('.J_ItemWrap').find('.card-actions').hide();
      });

      $('.J_GoodsWrap').on('click', '.J_AddToDrawer', function(ev) {
        ev.preventDefault();
        if (!isLogin) {
            $('.login').trigger('click');
            return false;
        };

        var goodsId = $(this).parent().attr('data-id');
        if (!parseInt(goodsId)) {
            return false;
        };

        var goodsCover = $(this).closest('.J_GoodsWrap').find('.J_GoodsPic');
        var goodsCoverSrc = goodsCover.attr('src');
        var goodsStyle = goodsCover.attr('style');

        $('#J_goodsCoverPreview').attr('src', goodsCoverSrc);
        $('#J_goodsCoverPreview').attr('data-goods-id', goodsId);
        $('#J_goodsCoverPreview').attr('style', goodsStyle);
        $('#add_drawer').trigger('click');
      });

      $('.carousel').carousel();
    });
  </script>
</html>